package com.rattsoftware.client.service;

import java.util.List;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
import com.rattsoftware.server.admin.model.Permission;
import com.rattsoftware.server.admin.model.Role;
import com.rattsoftware.server.admin.model.exceptions.RattsSecurityException;
import com.rattsoftware.server.admin.model.paging.PagingLoadConfig;
import com.rattsoftware.server.admin.model.paging.PagingLoadResult;

/**
 * This interface defines the client side contract for the Permission Service.
 */
@RemoteServiceRelativePath("roleService")
public interface RoleService extends RemoteService {
	
	/**
	 * Fetches all the system <tt>Roles.</tt>
	 * 
	 * @return <tt>List</tt> of <tt>Roles.</tt>
	 * @throws RattsSecurityException For any <tt>security related</tt> that occurs on the <tt>service layer.</tt>
	 */
	List<Role> getRoles() throws RattsSecurityException;
	
	/**
	 * Saves a dirty or new <tt>Role</tt>.
	 * 
	 * @param role <tt>Role</tt> to save.
	 * @throws RattsSecurityException For any <tt>security related</tt> that occurs on the <tt>service layer.</tt>
	 */
	void saveRole(Role role) throws RattsSecurityException;
	
	/**
	 * Deletes a given <tt>Role</tt>.
	 * 
	 * @param role <tt>Role</tt> to delete.
	 * @throws RattsSecurityException For any <tt>security related</tt> that occurs on the <tt>service layer.</tt>
	 */
	void deleteRole(Role role) throws RattsSecurityException;
	
	/**
	 * Fetches all the system <tt>Permissions.</tt>
	 * 
	 * @return <tt>List</tt> of <tt>Permissions.</tt>
	 * @throws RattsSecurityException For any <tt>security related</tt> that occurs on the <tt>service layer.</tt>
	 */
	List<Permission> getPermissions() throws RattsSecurityException;
	
	/**
	 * Saves a dirty or new <tt>Permission.</tt>
	 * 
	 * @param permission <tt>Permission</tt> to save.
	 * @throws RattsSecurityException For any <tt>security related</tt> that occurs on the <tt>service layer.</tt>
	 */
	void savePermission(Permission permission) throws RattsSecurityException;
	
	/**
	 * Deletes a given <tt>Permission.</tt>
	 * 
	 * @param permission <tt>Permission</tt> to delete.
	 * @throws RattsSecurityException For any <tt>security related</tt> that occurs on the <tt>service layer.</tt>
	 */
	void deletePermission(Permission permission) throws RattsSecurityException;
	
	/**
	 * Get a paged list of the roles mapped to the specified user
	 * @param userId
	 * @param pagingLoadConfig
	 * @return
	 */
    PagingLoadResult<Role> getMappedRoles(String userId, PagingLoadConfig pagingLoadConfig) throws RattsSecurityException;

    /**
     * Get a paged list of the roles NOT mapped to the specified user
     * @param userId
     * @param pagingLoadConfig
     * @return
     */
    public PagingLoadResult<Role> getUnMappedRoles(String userId, PagingLoadConfig pagingLoadConfig) throws RattsSecurityException;
    
	/**
	 * Updates the roles currently mapped to the specified user.
	 * @param userId Integer id of specified user
	 * @param rolesToAdd List of roles to add to the user
	 * @param rolesToDelete List of roles to delete from the user
	 * @throws OpenXDataSecurityException
	 */
	void saveMappedRoles(String userId, List<Role> rolesToAdd, List<Role> rolesToDelete) throws RattsSecurityException;
}
